{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e13f3b03",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>数量</th>\n",
       "      <th>产品名</th>\n",
       "      <th>是否自产</th>\n",
       "      <th>样品数量</th>\n",
       "      <th>样品良好率</th>\n",
       "      <th>价格</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100001000.0</td>\n",
       "      <td>104.0</td>\n",
       "      <td>沙发</td>\n",
       "      <td>Y</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>100002000.0</td>\n",
       "      <td>197.0</td>\n",
       "      <td>椅子</td>\n",
       "      <td>N</td>\n",
       "      <td>3</td>\n",
       "      <td>1.5</td>\n",
       "      <td>--</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100003000.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>床头柜</td>\n",
       "      <td>N</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>850</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>100004000.0</td>\n",
       "      <td>201.0</td>\n",
       "      <td>电脑</td>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>203.0</td>\n",
       "      <td>电视</td>\n",
       "      <td>Y</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>3600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>100006000.0</td>\n",
       "      <td>207.0</td>\n",
       "      <td>洗衣机</td>\n",
       "      <td>Y</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>100007000.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>电冰箱</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>HURLEY</td>\n",
       "      <td>950</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>100008000.0</td>\n",
       "      <td>213.0</td>\n",
       "      <td>书柜</td>\n",
       "      <td>Y</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>100009000.0</td>\n",
       "      <td>215.0</td>\n",
       "      <td>大衣柜</td>\n",
       "      <td>Y</td>\n",
       "      <td>na</td>\n",
       "      <td>2</td>\n",
       "      <td>1800</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            编号     数量  产品名 是否自产 样品数量   样品良好率    价格\n",
       "0  100001000.0  104.0   沙发    Y    3       1  1000\n",
       "1  100002000.0  197.0   椅子    N    3     1.5    --\n",
       "2  100003000.0    NaN  床头柜    N  NaN       1   850\n",
       "3  100004000.0  201.0   电脑   12    1     NaN  2700\n",
       "4          NaN  203.0   电视    Y    3       2  3600\n",
       "5  100006000.0  207.0  洗衣机    Y  NaN       1   800\n",
       "6  100007000.0    NaN  电冰箱  NaN    2  HURLEY   950\n",
       "7  100008000.0  213.0   书柜    Y    1       1   NaN\n",
       "8  100009000.0  215.0  大衣柜    Y   na       2  1800"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "mydf1 = pd.read_excel('mybook1.xls',sheet_name=0)\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "4edd5434",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>数量</th>\n",
       "      <th>产品名</th>\n",
       "      <th>是否自产</th>\n",
       "      <th>样品数量</th>\n",
       "      <th>样品良好率</th>\n",
       "      <th>价格</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100001000.0</td>\n",
       "      <td>104.0</td>\n",
       "      <td>沙发</td>\n",
       "      <td>Y</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>100002000.0</td>\n",
       "      <td>197.0</td>\n",
       "      <td>椅子</td>\n",
       "      <td>N</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.5</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100003000.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>床头柜</td>\n",
       "      <td>N</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>850.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>100004000.0</td>\n",
       "      <td>201.0</td>\n",
       "      <td>电脑</td>\n",
       "      <td>12</td>\n",
       "      <td>1.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2700.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>203.0</td>\n",
       "      <td>电视</td>\n",
       "      <td>Y</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2</td>\n",
       "      <td>3600.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>100006000.0</td>\n",
       "      <td>207.0</td>\n",
       "      <td>洗衣机</td>\n",
       "      <td>Y</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>800.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>100007000.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>电冰箱</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2.0</td>\n",
       "      <td>HURLEY</td>\n",
       "      <td>950.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>100008000.0</td>\n",
       "      <td>213.0</td>\n",
       "      <td>书柜</td>\n",
       "      <td>Y</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>100009000.0</td>\n",
       "      <td>215.0</td>\n",
       "      <td>大衣柜</td>\n",
       "      <td>Y</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "      <td>1800.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            编号     数量  产品名 是否自产  样品数量   样品良好率      价格\n",
       "0  100001000.0  104.0   沙发    Y   3.0       1  1000.0\n",
       "1  100002000.0  197.0   椅子    N   3.0     1.5     NaN\n",
       "2  100003000.0    NaN  床头柜    N   NaN       1   850.0\n",
       "3  100004000.0  201.0   电脑   12   1.0     NaN  2700.0\n",
       "4          NaN  203.0   电视    Y   3.0       2  3600.0\n",
       "5  100006000.0  207.0  洗衣机    Y   NaN       1   800.0\n",
       "6  100007000.0    NaN  电冰箱  NaN   2.0  HURLEY   950.0\n",
       "7  100008000.0  213.0   书柜    Y   1.0       1     NaN\n",
       "8  100009000.0  215.0  大衣柜    Y   NaN       2  1800.0"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "missing_values = [\"n/a\",\"na\",\"--\"]\n",
    "mydf1 = pd.read_excel('mybook1.xls',sheet_name=0,na_values=missing_values)\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "3cd7a9b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>数量</th>\n",
       "      <th>产品名</th>\n",
       "      <th>是否自产</th>\n",
       "      <th>样品数量</th>\n",
       "      <th>样品良好率</th>\n",
       "      <th>价格</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100001000.0</td>\n",
       "      <td>104.0</td>\n",
       "      <td>沙发</td>\n",
       "      <td>Y</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            编号     数量 产品名 是否自产  样品数量 样品良好率      价格\n",
       "0  100001000.0  104.0  沙发    Y   3.0     1  1000.0"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydf2 = mydf1.dropna(inplace=True)\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "5476f42d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>数量</th>\n",
       "      <th>产品名</th>\n",
       "      <th>是否自产</th>\n",
       "      <th>样品数量</th>\n",
       "      <th>样品良好率</th>\n",
       "      <th>价格</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>100001000.0</td>\n",
       "      <td>104.0</td>\n",
       "      <td>沙发</td>\n",
       "      <td>Y</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>100002000.0</td>\n",
       "      <td>197.0</td>\n",
       "      <td>椅子</td>\n",
       "      <td>N</td>\n",
       "      <td>3.0</td>\n",
       "      <td>1.5</td>\n",
       "      <td>18.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>100003000.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>床头柜</td>\n",
       "      <td>N</td>\n",
       "      <td>18.0</td>\n",
       "      <td>1</td>\n",
       "      <td>850.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>100004000.0</td>\n",
       "      <td>201.0</td>\n",
       "      <td>电脑</td>\n",
       "      <td>12</td>\n",
       "      <td>1.0</td>\n",
       "      <td>18</td>\n",
       "      <td>2700.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>18.0</td>\n",
       "      <td>203.0</td>\n",
       "      <td>电视</td>\n",
       "      <td>Y</td>\n",
       "      <td>3.0</td>\n",
       "      <td>2</td>\n",
       "      <td>3600.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>100006000.0</td>\n",
       "      <td>207.0</td>\n",
       "      <td>洗衣机</td>\n",
       "      <td>Y</td>\n",
       "      <td>18.0</td>\n",
       "      <td>1</td>\n",
       "      <td>800.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>100007000.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>电冰箱</td>\n",
       "      <td>18</td>\n",
       "      <td>2.0</td>\n",
       "      <td>HURLEY</td>\n",
       "      <td>950.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>100008000.0</td>\n",
       "      <td>213.0</td>\n",
       "      <td>书柜</td>\n",
       "      <td>Y</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1</td>\n",
       "      <td>18.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>100009000.0</td>\n",
       "      <td>215.0</td>\n",
       "      <td>大衣柜</td>\n",
       "      <td>Y</td>\n",
       "      <td>18.0</td>\n",
       "      <td>2</td>\n",
       "      <td>1800.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            编号     数量  产品名 是否自产  样品数量   样品良好率      价格\n",
       "0  100001000.0  104.0   沙发    Y   3.0       1  1000.0\n",
       "1  100002000.0  197.0   椅子    N   3.0     1.5    18.0\n",
       "2  100003000.0   18.0  床头柜    N  18.0       1   850.0\n",
       "3  100004000.0  201.0   电脑   12   1.0      18  2700.0\n",
       "4         18.0  203.0   电视    Y   3.0       2  3600.0\n",
       "5  100006000.0  207.0  洗衣机    Y  18.0       1   800.0\n",
       "6  100007000.0   18.0  电冰箱   18   2.0  HURLEY   950.0\n",
       "7  100008000.0  213.0   书柜    Y   1.0       1    18.0\n",
       "8  100009000.0  215.0  大衣柜    Y  18.0       2  1800.0"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydf3 = mydf1.fillna(18)\n",
    "mydf3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "8be1f68e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    100001000.0\n",
       "1    100002000.0\n",
       "2    100003000.0\n",
       "3    100004000.0\n",
       "4    100008000.0\n",
       "5    100006000.0\n",
       "6    100007000.0\n",
       "7    100008000.0\n",
       "8    100009000.0\n",
       "Name: 编号, dtype: float64"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydf4 = mydf1['编号'].fillna(100008000.0)\n",
    "mydf4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "a189b4fb",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\18027\\AppData\\Local\\Temp\\ipykernel_2856\\3202088426.py:6: FutureWarning: errors='ignore' is deprecated and will raise in a future version. Use to_datetime without passing `errors` and catch exceptions explicitly instead\n",
      "  mydf['日期'] = pd.to_datetime(mydf['日期'], errors='ignore')\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>水果名</th>\n",
       "      <th>价格</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2021/6/01</td>\n",
       "      <td>香蕉</td>\n",
       "      <td>3.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2021/6/02</td>\n",
       "      <td>苹果</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20210603</td>\n",
       "      <td>挑子</td>\n",
       "      <td>4.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          日期 水果名   价格\n",
       "0  2021/6/01  香蕉  3.5\n",
       "1  2021/6/02  苹果  6.0\n",
       "2   20210603  挑子  4.5"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "data={\"日期\":['2021/6/01','2021/6/02','20210603'],\n",
    "     \"水果名\":['香蕉','苹果','挑子'],\n",
    "     \"价格\":[3.5,6,4.5]}\n",
    "mydf = pd.DataFrame(data)\n",
    "mydf['日期'] = pd.to_datetime(mydf['日期'], errors='ignore')\n",
    "mydf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "e2612d22",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "time data \"2021/6/01\" doesn't match format \"%Y%m%d\", at position 0. You might want to try:\n    - passing `format` if your strings have a consistent format;\n    - passing `format='ISO8601'` if your strings are all ISO8601 but not necessarily in exactly the same format;\n    - passing `format='mixed'`, and the format will be inferred for each element individually. You might want to use `dayfirst` alongside this.",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[29], line 2\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpandas\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mpd\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m mydf[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m日期\u001b[39m\u001b[38;5;124m'\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[43mpd\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mto_datetime\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmydf\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m日期\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[38;5;28;43mformat\u001b[39;49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m%\u001b[39;49m\u001b[38;5;124;43mY\u001b[39;49m\u001b[38;5;124;43m%\u001b[39;49m\u001b[38;5;124;43mm\u001b[39;49m\u001b[38;5;132;43;01m%d\u001b[39;49;00m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m      3\u001b[0m mydf\n",
      "File \u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\pandas\\core\\tools\\datetimes.py:1067\u001b[0m, in \u001b[0;36mto_datetime\u001b[1;34m(arg, errors, dayfirst, yearfirst, utc, format, exact, unit, infer_datetime_format, origin, cache)\u001b[0m\n\u001b[0;32m   1065\u001b[0m         result \u001b[38;5;241m=\u001b[39m arg\u001b[38;5;241m.\u001b[39mmap(cache_array)\n\u001b[0;32m   1066\u001b[0m     \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m-> 1067\u001b[0m         values \u001b[38;5;241m=\u001b[39m \u001b[43mconvert_listlike\u001b[49m\u001b[43m(\u001b[49m\u001b[43marg\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_values\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mformat\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m   1068\u001b[0m         result \u001b[38;5;241m=\u001b[39m arg\u001b[38;5;241m.\u001b[39m_constructor(values, index\u001b[38;5;241m=\u001b[39marg\u001b[38;5;241m.\u001b[39mindex, name\u001b[38;5;241m=\u001b[39marg\u001b[38;5;241m.\u001b[39mname)\n\u001b[0;32m   1069\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(arg, (ABCDataFrame, abc\u001b[38;5;241m.\u001b[39mMutableMapping)):\n",
      "File \u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\pandas\\core\\tools\\datetimes.py:433\u001b[0m, in \u001b[0;36m_convert_listlike_datetimes\u001b[1;34m(arg, format, name, utc, unit, errors, dayfirst, yearfirst, exact)\u001b[0m\n\u001b[0;32m    431\u001b[0m \u001b[38;5;66;03m# `format` could be inferred, or user didn't ask for mixed-format parsing.\u001b[39;00m\n\u001b[0;32m    432\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mformat\u001b[39m \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mformat\u001b[39m \u001b[38;5;241m!=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmixed\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[1;32m--> 433\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_array_strptime_with_fallback\u001b[49m\u001b[43m(\u001b[49m\u001b[43marg\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mname\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mutc\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mformat\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mexact\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43merrors\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    435\u001b[0m result, tz_parsed \u001b[38;5;241m=\u001b[39m objects_to_datetime64(\n\u001b[0;32m    436\u001b[0m     arg,\n\u001b[0;32m    437\u001b[0m     dayfirst\u001b[38;5;241m=\u001b[39mdayfirst,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    441\u001b[0m     allow_object\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m,\n\u001b[0;32m    442\u001b[0m )\n\u001b[0;32m    444\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m tz_parsed \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m    445\u001b[0m     \u001b[38;5;66;03m# We can take a shortcut since the datetime64 numpy array\u001b[39;00m\n\u001b[0;32m    446\u001b[0m     \u001b[38;5;66;03m# is in UTC\u001b[39;00m\n",
      "File \u001b[1;32m~\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\pandas\\core\\tools\\datetimes.py:467\u001b[0m, in \u001b[0;36m_array_strptime_with_fallback\u001b[1;34m(arg, name, utc, fmt, exact, errors)\u001b[0m\n\u001b[0;32m    456\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_array_strptime_with_fallback\u001b[39m(\n\u001b[0;32m    457\u001b[0m     arg,\n\u001b[0;32m    458\u001b[0m     name,\n\u001b[1;32m   (...)\u001b[0m\n\u001b[0;32m    462\u001b[0m     errors: \u001b[38;5;28mstr\u001b[39m,\n\u001b[0;32m    463\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Index:\n\u001b[0;32m    464\u001b[0m \u001b[38;5;250m    \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[0;32m    465\u001b[0m \u001b[38;5;124;03m    Call array_strptime, with fallback behavior depending on 'errors'.\u001b[39;00m\n\u001b[0;32m    466\u001b[0m \u001b[38;5;124;03m    \"\"\"\u001b[39;00m\n\u001b[1;32m--> 467\u001b[0m     result, tz_out \u001b[38;5;241m=\u001b[39m \u001b[43marray_strptime\u001b[49m\u001b[43m(\u001b[49m\u001b[43marg\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfmt\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mexact\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mexact\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43merrors\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43merrors\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mutc\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mutc\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m    468\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m tz_out \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m    469\u001b[0m         unit \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mdatetime_data(result\u001b[38;5;241m.\u001b[39mdtype)[\u001b[38;5;241m0\u001b[39m]\n",
      "File \u001b[1;32mstrptime.pyx:501\u001b[0m, in \u001b[0;36mpandas._libs.tslibs.strptime.array_strptime\u001b[1;34m()\u001b[0m\n",
      "File \u001b[1;32mstrptime.pyx:451\u001b[0m, in \u001b[0;36mpandas._libs.tslibs.strptime.array_strptime\u001b[1;34m()\u001b[0m\n",
      "File \u001b[1;32mstrptime.pyx:583\u001b[0m, in \u001b[0;36mpandas._libs.tslibs.strptime._parse_with_format\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;31mValueError\u001b[0m: time data \"2021/6/01\" doesn't match format \"%Y%m%d\", at position 0. You might want to try:\n    - passing `format` if your strings have a consistent format;\n    - passing `format='ISO8601'` if your strings are all ISO8601 but not necessarily in exactly the same format;\n    - passing `format='mixed'`, and the format will be inferred for each element individually. You might want to use `dayfirst` alongside this."
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "mydf['日期'] = pd.to_datetime(mydf['日期'],format='%Y%m%d')\n",
    "mydf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e6c6b903",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>李明</td>\n",
       "      <td>男</td>\n",
       "      <td>14</td>\n",
       "      <td>115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张亮</td>\n",
       "      <td>男</td>\n",
       "      <td>113</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周可佳</td>\n",
       "      <td>女</td>\n",
       "      <td>15</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>王瑞</td>\n",
       "      <td>女</td>\n",
       "      <td>104</td>\n",
       "      <td>135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>刘伦瑞</td>\n",
       "      <td>男</td>\n",
       "      <td>112</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    姓名 性别   年龄   成绩\n",
       "0   李明  男   14  115\n",
       "1   张亮  男  113   89\n",
       "2  周可佳  女   15   98\n",
       "3   王瑞  女  104  135\n",
       "4  刘伦瑞  男  112   94"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "data={\n",
    "    \"姓名\":['李明','张亮','周可佳','王瑞','刘伦瑞'],\n",
    "    \"性别\":['男','男','女','女','男'],\n",
    "    \"年龄\":[14,113,15,104,112],\n",
    "    \"成绩\":[115,89,98,135,94]\n",
    "}\n",
    "mydf1 = pd.DataFrame(data)\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c67dad85",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>李明</td>\n",
       "      <td>男</td>\n",
       "      <td>14</td>\n",
       "      <td>115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张亮</td>\n",
       "      <td>男</td>\n",
       "      <td>15</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周可佳</td>\n",
       "      <td>女</td>\n",
       "      <td>15</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>王瑞</td>\n",
       "      <td>女</td>\n",
       "      <td>104</td>\n",
       "      <td>135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>刘伦瑞</td>\n",
       "      <td>男</td>\n",
       "      <td>112</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    姓名 性别   年龄   成绩\n",
       "0   李明  男   14  115\n",
       "1   张亮  男   15   89\n",
       "2  周可佳  女   15   98\n",
       "3   王瑞  女  104  135\n",
       "4  刘伦瑞  男  112   94"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydf1.loc[1,'年龄'] = 15\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "893692ec",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>李明</td>\n",
       "      <td>男</td>\n",
       "      <td>14</td>\n",
       "      <td>115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张亮</td>\n",
       "      <td>男</td>\n",
       "      <td>15</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周可佳</td>\n",
       "      <td>女</td>\n",
       "      <td>15</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>王瑞</td>\n",
       "      <td>女</td>\n",
       "      <td>16</td>\n",
       "      <td>135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>刘伦瑞</td>\n",
       "      <td>男</td>\n",
       "      <td>16</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    姓名 性别  年龄   成绩\n",
       "0   李明  男  14  115\n",
       "1   张亮  男  15   89\n",
       "2  周可佳  女  15   98\n",
       "3   王瑞  女  16  135\n",
       "4  刘伦瑞  男  16   94"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for x in mydf1.index:\n",
    "    if mydf1.loc[x,'年龄'] >100:\n",
    "        mydf1.loc[x,'年龄'] = 16\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "f49b3e68",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张亮</td>\n",
       "      <td>男</td>\n",
       "      <td>15</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周可佳</td>\n",
       "      <td>女</td>\n",
       "      <td>15</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>刘伦瑞</td>\n",
       "      <td>男</td>\n",
       "      <td>16</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    姓名 性别  年龄  成绩\n",
       "1   张亮  男  15  89\n",
       "2  周可佳  女  15  98\n",
       "4  刘伦瑞  男  16  94"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for x in mydf1.index:\n",
    "    if mydf1.loc[x,'成绩'] >100:\n",
    "        mydf1.drop(x)\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "43bd406b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张亮</td>\n",
       "      <td>男</td>\n",
       "      <td>15</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周可佳</td>\n",
       "      <td>女</td>\n",
       "      <td>15</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>刘伦瑞</td>\n",
       "      <td>男</td>\n",
       "      <td>16</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    姓名 性别  年龄  成绩\n",
       "1   张亮  男  15  89\n",
       "2  周可佳  女  15  98\n",
       "4  刘伦瑞  男  16  94"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "44414780",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>李明</td>\n",
       "      <td>男</td>\n",
       "      <td>14</td>\n",
       "      <td>95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张亮</td>\n",
       "      <td>男</td>\n",
       "      <td>13</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周可佳</td>\n",
       "      <td>女</td>\n",
       "      <td>15</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>王瑞</td>\n",
       "      <td>女</td>\n",
       "      <td>14</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>刘伦瑞</td>\n",
       "      <td>男</td>\n",
       "      <td>12</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>王瑞</td>\n",
       "      <td>女</td>\n",
       "      <td>14</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>刘伦瑞</td>\n",
       "      <td>男</td>\n",
       "      <td>12</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    姓名 性别  年龄  成绩\n",
       "0   李明  男  14  95\n",
       "1   张亮  男  13  89\n",
       "2  周可佳  女  15  98\n",
       "3   王瑞  女  14  35\n",
       "4  刘伦瑞  男  12  94\n",
       "5   王瑞  女  14  35\n",
       "6  刘伦瑞  男  12  94"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 删除重复的数据\n",
    "import pandas as pd\n",
    "data={\n",
    "    \"姓名\":['李明','张亮','周可佳','王瑞','刘伦瑞','王瑞','刘伦瑞'],\n",
    "    \"性别\":['男','男','女','女','男','女','男'],\n",
    "    \"年龄\":[14,13,15,14,12,14,12],\n",
    "    \"成绩\":[95,89,98,35,94,35,94]\n",
    "}\n",
    "mydf1 = pd.DataFrame(data)\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "0c8336ef",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    False\n",
       "1    False\n",
       "2    False\n",
       "3    False\n",
       "4    False\n",
       "5     True\n",
       "6     True\n",
       "dtype: bool"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydf1.duplicated()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "32a94bbb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>成绩</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>李明</td>\n",
       "      <td>男</td>\n",
       "      <td>14</td>\n",
       "      <td>95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张亮</td>\n",
       "      <td>男</td>\n",
       "      <td>13</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周可佳</td>\n",
       "      <td>女</td>\n",
       "      <td>15</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>王瑞</td>\n",
       "      <td>女</td>\n",
       "      <td>14</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>刘伦瑞</td>\n",
       "      <td>男</td>\n",
       "      <td>12</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    姓名 性别  年龄  成绩\n",
       "0   李明  男  14  95\n",
       "1   张亮  男  13  89\n",
       "2  周可佳  女  15  98\n",
       "3   王瑞  女  14  35\n",
       "4  刘伦瑞  男  12  94"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydf1.drop_duplicates(inplace=True)\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "1ee38fea",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>赵可佳</td>\n",
       "      <td>女</td>\n",
       "      <td>25</td>\n",
       "      <td>5869.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张可</td>\n",
       "      <td>男</td>\n",
       "      <td>28</td>\n",
       "      <td>7256.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周远</td>\n",
       "      <td>女</td>\n",
       "      <td>21</td>\n",
       "      <td>6895.89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>徐南</td>\n",
       "      <td>男</td>\n",
       "      <td>30</td>\n",
       "      <td>7289.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     A  B   C        D\n",
       "0  赵可佳  女  25  5869.32\n",
       "1   张可  男  28  7256.34\n",
       "2   周远  女  21  6895.89\n",
       "3   徐南  男  30  7289.72"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "data={\"A\":[\"赵可佳\",\"张可\",\"周远\",\"徐南\"],\n",
    "    \"B\":['女','男','女','男'],\n",
    "    \"C\":[25,28,21,30],\n",
    "    \"D\":[5869.32,7256.34,6895.89,7289.72]}\n",
    "mydf1 = pd.DataFrame(data)\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "eb145c98",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>工资</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>赵可佳</td>\n",
       "      <td>女</td>\n",
       "      <td>25</td>\n",
       "      <td>5869.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张可</td>\n",
       "      <td>男</td>\n",
       "      <td>28</td>\n",
       "      <td>7256.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周远</td>\n",
       "      <td>女</td>\n",
       "      <td>21</td>\n",
       "      <td>6895.89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>徐南</td>\n",
       "      <td>男</td>\n",
       "      <td>30</td>\n",
       "      <td>7289.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    姓名 性别  年龄       工资\n",
       "0  赵可佳  女  25  5869.32\n",
       "1   张可  男  28  7256.34\n",
       "2   周远  女  21  6895.89\n",
       "3   徐南  男  30  7289.72"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydf1.columns = ['姓名','性别','年龄','工资']\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "5cd53bb7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>职工姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>工资</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>王丽</td>\n",
       "      <td>女</td>\n",
       "      <td>25</td>\n",
       "      <td>5869.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张可</td>\n",
       "      <td>男</td>\n",
       "      <td>28</td>\n",
       "      <td>7256.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周远</td>\n",
       "      <td>女</td>\n",
       "      <td>21</td>\n",
       "      <td>6895.89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>徐南</td>\n",
       "      <td>男</td>\n",
       "      <td>30</td>\n",
       "      <td>7289.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  职工姓名 性别  年龄       工资\n",
       "0   王丽  女  25  5869.32\n",
       "1   张可  男  28  7256.34\n",
       "2   周远  女  21  6895.89\n",
       "3   徐南  男  30  7289.72"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydf1.rename(columns={'姓名':'职工姓名'},inplace=True)\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "c078524b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "      <th>性别</th>\n",
       "      <th>年龄</th>\n",
       "      <th>工资</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>王丽</td>\n",
       "      <td>女</td>\n",
       "      <td>25</td>\n",
       "      <td>5869.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>张可</td>\n",
       "      <td>男</td>\n",
       "      <td>28</td>\n",
       "      <td>7256.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>周远</td>\n",
       "      <td>女</td>\n",
       "      <td>21</td>\n",
       "      <td>6895.89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>徐南</td>\n",
       "      <td>男</td>\n",
       "      <td>30</td>\n",
       "      <td>7289.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   姓名 性别  年龄       工资\n",
       "0  王丽  女  25  5869.32\n",
       "1  张可  男  28  7256.34\n",
       "2  周远  女  21  6895.89\n",
       "3  徐南  男  30  7289.72"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydf1.replace('赵可佳','王丽',inplace=True)\n",
    "mydf1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "57d25b8b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "85d8ea4a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
